<?php
Yii::import('Cms.components.widgets.BaseCmsWidget');
class CmsMetadata extends BaseCmsWidget {
    
    public function run(){
        $models = $this->getActiveDataProvider()->getData();
        if (count($models))
        {
            $model = $models[0];
            $title = Yii::app()->controller->pageTitle;
            if (!empty($model->title))
                $title = $model->title;
            Yii::app()->clientScript->registerMetaTag($title, 'title');
            if (!empty($model->keywords))
                Yii::app()->clientScript->registerMetaTag($model->keywords, 'keywords');
            if (!empty($model->description))
                Yii::app()->clientScript->registerMetaTag($model->description, 'description');
        }
        return '';
    }
    
    // this widget does not have layout
    public function getSelectedLayout() {
        return null;
    }
    
    // return the url to edit text content
    public function getEditUrl($params = array()){
        $params['page_widget_id'] = $this->pageWidgetId;
        $params['id'] = $this->dataSettings['params'][':id'];
        
        return url('/Cms/widgets/cmsMetadata/update', $params);
    }
}
